package com.angis.fx.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class XtszDBHelper extends ObjectDBHelper {
	
	public static final String PK_XID = "xid";
	public static final String COLUMN_SECOND = "second";
	public static final String COLUMN_METER = "meter";
	public static final String COLUMN_HOST = "host";
	
	public static final String TABLE_NAME = "xtsz";

	public XtszDBHelper(Context context) {
		super(context);
	}
	
	public Cursor find() {
		if(null == readDB) {
			readDB = dbHelper.getReadableDatabase();
		}
		return readDB.query(TABLE_NAME, new String[]{COLUMN_SECOND, COLUMN_METER, COLUMN_HOST}, PK_XID + "=?", new String[]{"1"}, null, null, null);
		
	}
	
	public long insert(String pSecond, String pMeter, String pHost) {
		ContentValues lValues = new ContentValues();
		lValues.put(PK_XID, "1");
		lValues.put(COLUMN_SECOND, pSecond);
		lValues.put(COLUMN_METER, pMeter);
		lValues.put(COLUMN_HOST, pHost);
		return this.insert(TABLE_NAME, lValues);
	}
	
	public void update(String pSecond, String pMeter, String pHost){
		if (null == writeDB) {
			writeDB = dbHelper.getWritableDatabase();
		}
		ContentValues lValues = new ContentValues();
		lValues.put(PK_XID, "1");
		if(null != pSecond && pSecond.length() > 0) {
			lValues.put(COLUMN_SECOND, pSecond);
		}
		if(null != pMeter && pMeter.length() > 0) {
			lValues.put(COLUMN_METER, pMeter);
		}
		if(null != pHost && pHost.length() > 0) {
			lValues.put(COLUMN_HOST, pHost);
		}
		writeDB.update(TABLE_NAME, lValues, PK_XID+"=?", new String[]{"1"});
	}

}
